package com.barbeque.mall.controller;

import com.barbeque.mall.bean.BasePageInfo;
import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.brand.MarketBrand;
import com.barbeque.mall.bean.brand.MarketBrandBO;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.service.BrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author Tezel
 * @since 2022/07/15 20:28
 */

@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {

    @Autowired
    BrandService brandService;

    @RequiresPermissions("admin:brand:list")
    @RequestMapping("list")
    public BaseRespVo list(Integer id,String name ,BasePageInfo info) {
        CommonData<MarketBrand> data = brandService.query(id,name,info);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }

    @RequiresPermissions("admin:brand:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketBrandBO marketBrandBO) {
        MarketBrand data = brandService.create(marketBrandBO);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }

    @RequiresPermissions("admin:brand:update")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public BaseRespVo update(@RequestBody MarketBrand marketBrand) {
        MarketBrand data = brandService.update(marketBrand);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }

    @RequiresPermissions("admin:brand:delete")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public BaseRespVo<Object> delete(@RequestBody MarketBrand marketBrand) {
        brandService.delete(marketBrand);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }


}
